package cn.ylz.ylmall.common.web;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @author pc
 */

@Getter
@AllArgsConstructor
public enum OrderCode {

    ORDER_CANCELLED(0,"订单被取消"),

    ORDER_NOTPAY(1,"订单未支付"),

    ORDER_PAID(2,"订单已付款"),

    ORDER_END(3,"订单已结束");

    private final Integer code;

    private final String name;

    public static OrderCode findEnumByCode(Integer code) {
        for (OrderCode orderCode : OrderCode.values()) {
            if (orderCode.getCode().equals(code)) {
                //如果需要直接返回name则更改返回类型为String,return statusEnum.name;
                return orderCode;
            }
        }
        throw new IllegalArgumentException("code is invalid");
    }


    public static OrderCode findEnumByName(String name) {
        for (OrderCode orderCode : OrderCode.values()) {
            if (orderCode.getName().equals(name)) {
                //如果需要直接返回name则更改返回类型为String,return statusEnum.name;
                return orderCode;
            }
        }
        throw new IllegalArgumentException("name is invalid");
    }
}
